package com.zshan.clinic.common.enums;

import com.zshan.clinic.common.util.string.StringUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 民族
 */
public enum EthnicityEnum {

    HAN("1", "汉族"),
    ZHUANG("2", "壮族"),
    HUI("3", "回族"),
    MAN("4", "满族"),
    MIAO("5", "苗族"),
    UYGHUR("6", "维吾尔族"),
    TIBETAN("7", "藏族"),
    MONGOL("8", "蒙古族"),
    DONG("9", "侗族"),
    YAO("10", "瑶族"),
    UNKNOWN("99", "未知");

    private final String value;
    private final String text;

    EthnicityEnum(String value, String text) {
        this.value = value;
        this.text = text;
    }

    public String getValue() {
        return this.value;
    }

    public String getText() {
        return this.text;
    }

    public static EthnicityEnum getValue(String value) {
        if (StringUtil.isBlank(value)) {
            return null;
        }
        for (EthnicityEnum e : values()) {
            if (value.equals(e.getValue())) {
                return e;
            }
        }
        return null;
    }

    public static String getText(String value) {
        if (StringUtil.isBlank(value)) {
            return null;
        }
        for (EthnicityEnum e : values()) {
            if (value.equals(e.getValue())) {
                return e.getText();
            }
        }
        return null;
    }

    public static boolean isValue(String value) {
        if (StringUtil.isBlank(value)) {
            return false;
        }
        for (EthnicityEnum e : values()) {
            if (value.equals(e.getValue())) {
                return true;
            }
        }
        return false;
    }

    public Map<String, String> toMap() {
        Map<String, String> map = new HashMap<>();
        map.put("value", this.value);
        map.put("text", this.text);
        return map;
    }

    public static List<Map<String, String>> allToMap() {
        List<Map<String, String>> list = new ArrayList<>();
        for (EthnicityEnum e : values()) {
            list.add(e.toMap());
        }
        return list;
    }
}

